Repository navigation
fix(telemetry): categorize every terminal automation failure (OSS-5810) - #766
Conversation
Guarantee bounded failure_stage/failure_kind on automation_run_failed and automation_run_dispatch_failed events, derived from the existing trigger_source vocabulary (callback->execution, dispatcher->dispatch, watchdog->watchdog) with an execution_error/dispatch_error fallback kind. Explicit caller properties still win and no raw error text is copied into telemetry. Watchdog SQL updates now sync the in-memory run before capture so verified execution failures/timeouts report the persisted status and derived kind instead of stale RUNNING/None. The dispatcher mirrors the same sync after mark_run_terminal, and unexpected dispatch-task exceptions now emit a categorized automation_run_failed event instead of failing silently. Co-authored-by: openhands <openhands@all-hands.dev>
Fixes the pyright reportArgumentType error from the backend CI check. Co-authored-by: openhands <openhands@all-hands.dev>
|
Warning Your comment is too long (maximum is 65536 characters), so the coverage report was not added. See the job log for how to reduce it. |
all-hands-bot
left a comment
There was a problem hiding this comment.
This review was posted by an AI agent (OpenHands).
Reviewed head d32f9f24a5bf097993c868d4731837c52bfbee67 against main in a clean checkout, with AGENTS.md and the repo review guide applied.
Scope: All changed files (telemetry.py, watchdog.py, dispatcher.py + tests) belong to this repository per the ownership boundaries in AGENTS.md. The PR description provides the design context the guide asks for on cross-cutting lifecycle changes: intent, before/after behavior, compatibility notes, and commit-pinned code references.
Verification:
- All required checks pass on this exact head (
unit-tests,backend,windows-tests, image builds). - Locally: all 36
tests/test_telemetry.pytests pass, the two newTestVerifyAndMarkRunTelemetrywatchdog tests pass (exit 1 →execution_error, exit -1 →timeout), andruff check/ruff format --checkare clean on all six changed files. The remaining local errors are Docker-fixture availability, covered by CI. - New tests exercise the real capture, DB, watchdog, and dispatcher paths with only the PostHog HTTP transport faked, matching the repo's evidence rule for lifecycle fixes.
Correctness checks (no material findings):
_ensure_failure_propertiesonly ever writes bounded stage/kind values; rawerror_detailtext is never copied into properties, and explicit caller-provided categories win. Verified against the callback, dispatcher, and watchdog capture sites.- The in-memory run syncs mirror the preceding conditional
UPDATE ... WHERE status = 'RUNNING'exactly: watchdog terminal branches set the same status the SQL writes (COMPLETEDiff exit_code == 0), anderror_detailis synced only on failure branches. Mutating the detached run object for telemetry reads follows an existing in-repo precedent (mark_deferred_runs_expireddoes the same forSKIPPEDruns); the object is not re-attached or reused for writes afterward, so no race or persisted-state drift is introduced. - The callback path refreshes the run after the terminal UPDATE before capturing, so
run_statusis now correct there, and theTimed out:reconcile path inrouter.pyis unaffected (dispatcher failures never carry that prefix). _execute_run_safeemits its event only on a genuine background-task exception, aftermark_run_terminalmarks the run FAILED, satisfying the fire-and-forget "owner that observes and records failure" checkpoint.run.automationis eagerly loaded by_poll_pending_runson this path.- Consent gating, distinct-id resolution, actor identity, and first-run outcome recording are unchanged; success events gain no failure properties.
- No schema or migration changes; behavior is driver-agnostic (SQLite local tests + PostgreSQL CI).
Every terminal failure path now emits a categorized event, and the fallback vocabulary stays closed even when no trigger source is supplied. Nothing blocking found.
✅ APPROVED
|
🚀 Released in 1.33.0. |
Summary
Implements the remaining OSS-5810 work: every terminal automation failure now emits bounded
failure_stage/failure_kindvalues so PostHog funnels can categorize failures and count unique users with >=1 success vs failure-only users. No existing open PR covered this (checked; #704failure_kindderivation is already merged and is built on, not duplicated).This PR was created by an AI agent (OpenHands) on behalf of the requester.
What was broken
FAILEDwith no usableerror_detailproducedautomation_run_failedwith no failure category at all.run_status: RUNNING, no derived kind)._execute_run_safe) marked runs FAILED with no telemetry event.failure_stage.Change
telemetry.py:_ensure_failure_propertiesguarantees boundedfailure_stage/failure_kindonautomation_run_failed/automation_run_dispatch_failed. Stage is derived from the stage that already determined the outcome (the same values first-run outcomes record):callback -> execution,dispatcher -> dispatch,watchdog -> watchdog. Kind falls back toexecution_error/dispatch_error. Explicit caller-provided values always win; raw error text is never copied into properties. Success events are untouched.watchdog.py: sync the in-memory run (status/error_detail) with the SQL update before capture in all three terminal branches, so run status and derived kinds (e.g.timeoutfor exit -1) reflect the persisted row.dispatcher.py: same sync in_fail;_execute_run_safenow emits a categorizedautomation_run_failed(dispatch/dispatch_error) after marking the run FAILED.Actor identity, consent checks, trigger/deployment context and explicit category overrides are preserved; only the external PostHog HTTP transport is faked in the new tests (the real capture code path, DB sessions and watchdog/dispatcher logic run for real).
Tests
New regression tests failed before the fix (9 failures: missing
failure_stage/ missing event) and pass after:tests/test_telemetry.py: parametrized terminal-failure categorization for callback/dispatcher/watchdog (via a real local capture server faking only PostHog transport), explicit-override preservation, no raw error/secret in payloads, success events gain no failure properties, and a unique-user aggregation test separating users with >=1 success from failure-only users.tests/test_watchdog.py: real_verify_and_mark_runverified-failure captures (exit 1 ->execution_error, exit -1 ->timeout).tests/test_dispatcher.py: real_execute_run_safefailure emits the categorized terminal event.Results:
tests/test_telemetry.py+tests/test_watchdog.py: 76 passedtests/test_dispatcher.py: 103 passed, 1 failed (TestDispatcherLoop::test_dispatcher_loop_dispatches_runs— pre-existing: also fails on cleanmain, verified viagit stash)tests/test_router.pycallback/cancel/first-run subset: 27 passed;tests/test_run_utils.py+tests/test_cancel_run.py: 17 passedruff checkandruff format --checkclean on changed filesLive local evidence (synthetic data only, local fake PostHog — not production)
Ran the real service locally (
uvicorn openhands.automation.app:app, SQLite, local auth,AUTOMATION_POSTHOG_HOSTpointed at a local capture server on 127.0.0.1), seeded two synthetic users with consent + RUNNING runs, then POSTed real callbacks:Captured payloads:
The watchdog live path stayed transient by design (local agent server unreachable -> verification retries, run left RUNNING), so watchdog terminal classification is evidenced by the real-capture tests above rather than a forced live run.
Not done here, per scope: no Linear state changes, no PostHog dashboard/funnel changes, PostHog-side distinct-id aliasing for already-sent anonymous events is out of scope for this repo change.